# Maintainer: Massimiliano Torromeo <massimiliano.torromeo@gmail.com>

pkgname=libimagequant
pkgver=4.2.2
pkgrel=2
pkgdesc="Library for high-quality conversion of RGBA images to 8-bit indexed-color (palette) images"
arch=('loong64' 'x86_64')
url="https://pngquant.org/lib/"
license=('BSD')
depends=('gcc-libs')
makedepends=('cargo' 'cargo-c')
source=("https://github.com/ImageOptim/libimagequant/archive/$pkgver/libimagequant-$pkgver.tar.gz")
sha256sums=('ff1a34d3df9a1a5e5c1fa3895c036a885dc7b9740d7fccdf57e9ed678b8fb3a3')

build() {
    cd "$srcdir/$pkgname-$pkgver/imagequant-sys"
    find -name Cargo.lock -exec rm -f {} \;
    mkdir -p .cargo
    cat > .cargo/config.toml <<EOF
[source.crates-io]
registry = "https://gitee.com/yetist/crates.io-index"
EOF
    cargo cbuild --release --prefix=/usr
}

check() {
    cd "$srcdir/$pkgname-$pkgver/imagequant-sys"
    cargo ctest --release
}

package() {
    cd "$srcdir/$pkgname-$pkgver/imagequant-sys"
    cargo cinstall --destdir="$pkgdir" --prefix=/usr --release
    install -Dm644 COPYRIGHT "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
    cd "$pkgdir"/usr/lib
    ln -s libimagequant.so.0.0.* libimagequant.so.0.0
    ln -s libimagequant.so.0.0 libimagequant.so.0
}
